package cn.bdqn.controller;

import cn.bdqn.pojo.Banner;
import cn.bdqn.pojo.Department;
import cn.bdqn.service.AnnouncementService;
import cn.bdqn.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 正文
 * @date 2020/6/25 - 10:56
 */
//部门
@Controller
@ResponseBody
@RequestMapping("Department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;
    //部门查询
    @RequestMapping("/list")
    public String getlist(){
        List<Department> list = departmentService.getList();
        return "list";
    }
    //跳转部门添加页面
    @RequestMapping("/add")
    public String add(){
        return "add";
    }
    //部门添加成功返回首页
    @RequestMapping("addusr")
    public String add(Department department) {
        departmentService.add(department);
        return "redirect:/list";
    }
    //根据id修改跳转修改页面
    @RequestMapping("/update/{id}")
    public String update(@PathVariable int id, Model model){
        List<Department> list=departmentService.getListById(id);
        model.addAttribute("list",list);
        return "update";
    }
    //修改成功返回首页
    @RequestMapping("/upd")
    public String upd(Department department){
        departmentService.update(department);
        return "redirect:/list";
    }
    //删除部门
    @RequestMapping("/delete/{id}")
    public String delete(@PathVariable int id){
        departmentService.delete(id);
        return "redirect:/list";
    }
}
